#include "widget.h"
#include "ui_widget.h"

#include <QDebug>

Widget::Widget(QWidget *parent)
    : QWidget(parent)
    , ui(new Ui::Widget)
{
    ui->setupUi(this);
}

Widget::~Widget()
{
    delete ui;
}

void Widget::ControlMove(int x, int y)
{
    ui->Button_Control->move(x,y);
}

void Widget::lockbutton(QPushButton *button, bool state)
{
    button->setEnabled(state);
}

void Widget::lockbutton(QPushButton *button)
{
    bool lo_state = button->isEnabled();
    if (lo_state)
    {
        lockbutton(button,false);
    }
    else
    {
        lockbutton(button,true);
    }
}


void Widget::on_Button_Up_clicked()
{
    //获取到target本身的geometry  target目标  geometry几何
    QRect lo_rect = ui->Button_Control->geometry();
    qDebug()<<lo_rect;
    int x=lo_rect.x();
    int y=lo_rect.y();
    y-=10;
    ControlMove(x,y);
}

void Widget::on_Button_Down_clicked()
{
    //获取到target本身的geometry  target目标  geometry几何
    QRect lo_rect = ui->Button_Control->geometry();
    qDebug()<<lo_rect;
    int x=lo_rect.x();
    int y=lo_rect.y();
    y+=10;
    ControlMove(x,y);
}

void Widget::on_Button_Left_clicked()
{
    //获取到target本身的geometry  target目标  geometry几何
    QRect lo_rect = ui->Button_Control->geometry();
    qDebug()<<lo_rect;
    int x=lo_rect.x();
    int y=lo_rect.y();
    x-=10;
    ControlMove(x,y);
}

void Widget::on_Button_Right_clicked()
{
    //获取到target本身的geometry  target目标  geometry几何
    QRect lo_rect = ui->Button_Control->geometry();
    qDebug()<<lo_rect;
    int x=lo_rect.x();
    int y=lo_rect.y();
    x+=10;
    ControlMove(x,y);
}


void Widget::on_Button_Up_2_clicked()
{
    //获取到target本身的geometry  target目标  geometry几何
    QRect lo_rect = ui->Button_Control->geometry();
    qDebug()<<lo_rect;
    //修改QRect左上角点的坐标 rect矩形
    lo_rect.setY(lo_rect.y()-5);
    //将QRect设置入button
    ui->Button_Control->setGeometry(lo_rect);
}

void Widget::on_Button_Down_2_clicked()
{
    //获取到target本身的geometry  target目标  geometry几何
    QRect lo_rect = ui->Button_Control->geometry();
    qDebug()<<lo_rect;
    //修改QRect左上角点的坐标 rect矩形
    lo_rect.setY(lo_rect.y()+5);
    //将QRect设置入button
    ui->Button_Control->setGeometry(lo_rect);
}

void Widget::on_Button_Left_2_clicked()
{
    //获取到target本身的geometry  target目标  geometry几何
    QRect lo_rect = ui->Button_Control->geometry();
    qDebug()<<lo_rect;
    //修改QRect左上角点的坐标 rect矩形
    lo_rect.setX(lo_rect.x()-5);
    //将QRect设置入button
    ui->Button_Control->setGeometry(lo_rect);
}

void Widget::on_Button_Right_2_clicked()
{
    //获取到target本身的geometry  target目标  geometry几何
    QRect lo_rect = ui->Button_Control->geometry();
    qDebug()<<lo_rect;
    //修改QRect左上角点的坐标 rect矩形
    lo_rect.setX(lo_rect.x()+5);
    //将QRect设置入button
    ui->Button_Control->setGeometry(lo_rect);
}

void Widget::on_Button_Up_3_clicked()
{
    //获取到target本身的geometry  target目标  geometry几何
    QRect lo_rect = ui->Button_Control->geometry();
    qDebug()<<lo_rect;
    //只修改QRect的Y坐标 rect矩形 width高 height宽
    ui->Button_Control->setGeometry(lo_rect.x(),lo_rect.y()-5,lo_rect.width(),lo_rect.height());
}

void Widget::on_Button_Down_3_clicked()
{
    //获取到target本身的geometry  target目标  geometry几何
    QRect lo_rect = ui->Button_Control->geometry();
    qDebug()<<lo_rect;
    //只修改QRect的Y坐标 rect矩形 width高 height宽
    ui->Button_Control->setGeometry(lo_rect.x(),lo_rect.y()+5,lo_rect.width(),lo_rect.height());
}

void Widget::on_Button_Left_3_clicked()
{
    //获取到target本身的geometry  target目标  geometry几何
    QRect lo_rect = ui->Button_Control->geometry();
    qDebug()<<lo_rect;
    //只修改QRect的Y坐标 rect矩形 width高 height宽
    ui->Button_Control->setGeometry(lo_rect.x()-5,lo_rect.y(),lo_rect.width(),lo_rect.height());
}

void Widget::on_Button_Right_3_clicked()
{
    //获取到target本身的geometry  target目标  geometry几何
    QRect lo_rect = ui->Button_Control->geometry();
    qDebug()<<lo_rect;
    //只修改QRect的Y坐标 rect矩形 width高 height宽
    ui->Button_Control->setGeometry(lo_rect.x()+5,lo_rect.y(),lo_rect.width(),lo_rect.height());
}



void Widget::on_Button_Control_clicked()
{
    //enable 使用 state状态
    lockbutton(ui->Button_Up);
    lockbutton(ui->Button_Down);
    lockbutton(ui->Button_Left);
    lockbutton(ui->Button_Right);

    lockbutton(ui->Button_Up_2);
    lockbutton(ui->Button_Down_2);
    lockbutton(ui->Button_Left_2);
    lockbutton(ui->Button_Right_2);

    lockbutton(ui->Button_Up_3);
    lockbutton(ui->Button_Down_3);
    lockbutton(ui->Button_Left_3);
    lockbutton(ui->Button_Right_3);

}
